package com.atguigu.gulimall.member.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

//自定义SpringSession的配置
@Configuration
public class GulimallSessionConfig {

    /**
     * 配置 JSESSIONID这个cookie
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        //配置JSessionID这个cookie的规则
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setDomainName("gulimall.com");//指定作用域（默认请求下只包含当前域名）
        cookieSerializer.setCookieName("GULISESSION");//指定cookie的名字key
        return cookieSerializer;
    }

    /**
     * 配置session的序列化规则:以JSON的形式
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }

}
